﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Concurrent;

public class AttackTargetManager : MonoBehaviour {
	public static AttackTargetManager instance;

	public List<GameObject> guns;//所有枪
	// public List<Image> weaponIcons;
	// public List<Image> weaponIcon_states;
	// public Sprite[] image_weaponIcon_states;

	public List<Image> outCircles;
	public List<Image> inCircles;
	public List<Image> Icons;

	// 近弱强止
	// 原色，蓝色，紫色，红色
	private Color32[] outCircleColors
	 = new Color32[]{new Color32(112,174,176,255), new Color32(199,223,245,255), new Color32(243,191,237,255), new Color32(244,157,153,255)};
	private Color32[] inCircleColors
	 = new Color32[]{new Color32(64,100,101,255), new Color32(52,100,143,255), new Color32(106,90,141,255), new Color32(145,57,53,255)};

	// new Vector4(64,100,101,1);




	private int[] weaponBaseTypes;
	
	private int[] attackStates;

	public static int disMin = 1;
	public static int hpMin = 2;
	public static int hpMax = 3;
	public static int stopAttack = 4;

	public static System.Action<string, string> SendMsgToDevice;

	/// <summary>
	/// Awake is called when the script instance is being loaded.
	/// </summary>
	void Awake()
	{
		instance = this;
	}



	// Use this for initialization
	void Start () {
		weaponBaseTypes = new int[guns.Count];
		for (int i = 0; i < guns.Count; i++)
		{
			GameObject gun = guns[i];
			WeaponInfo weaponInfo = gun.GetComponent<PlayerAttack>().weaponInfo;
			
			if(weaponInfo != null)
			{
				weaponBaseTypes[i] = weaponInfo.BaseType;
				
				// weaponIcons[i].sprite = Resources.Load("WeaponIcons/" + weaponInfo.Icon, typeof(Sprite)) as Sprite;
				
				// if(weaponBaseTypes[i] == 1)
				// {
					// weaponIcon_states[i].sprite = image_weaponIcon_states[0];
					outCircles[i].color = outCircleColors[0];
					inCircles[i].GetComponent<Image>().color = inCircleColors[0];
				// }
			}
		}

		// 第一个0为了填充位置而已
		attackStates = new int[]{0,1,1,1,1,1,1};
	}
	
	// Update is called once per frame
	void Update () {
		
	}


	public void OnClickOne()
	{
		ChangeAttackState(0, 1);
		
	}

	public void OnClickTwo()
	{
		ChangeAttackState(1, 2);
	}

	public void OnClickThree()
	{
		ChangeAttackState(2, 3);
	}

	public void OnClickFour()
	{
		ChangeAttackState(3, 4);
	}

	public void OnClickFive()
	{
		ChangeAttackState(4, 5);
	}

	public void OnClickSix()
	{
		ChangeAttackState(5, 6);
	}

	private void ChangeAttackState(int gunAndIconNum, int stateNum)
	{
		switch (weaponBaseTypes[gunAndIconNum])
		{
			case 1:
				if(guns[gunAndIconNum] != null)
				{
				print("点击了第" + gunAndIconNum + "个按钮");
				attackStates[stateNum] = attackStates[stateNum] % 4;
				attackStates[stateNum]++;
				guns[gunAndIconNum].GetComponent<PlayerAttack>().SetAttackState(attackStates[stateNum]);
				// weaponIcon_states[gunAndIconNum].sprite = image_weaponIcon_states[attackStates[stateNum] - 1];
				outCircles[gunAndIconNum].color = outCircleColors[attackStates[stateNum] - 1];
				inCircles[gunAndIconNum].color = inCircleColors[attackStates[stateNum] - 1];
				print(inCircleColors[attackStates[stateNum] - 1]);
				}
			break;
			case 2:
				// 第二类型武器
				if(SendMsgToDevice != null)
				{
					print("send");
					SendMsgToDevice(guns[gunAndIconNum].GetComponent<PlayerAttack>().weaponInfo.Name, guns[gunAndIconNum].gameObject.name);
				}
			break;
			case 3:
			// 第三类型武器
			break;
		}
		
	}

}
